<?php 
namespace App\Http\Controllers\Home;
use Session;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Home\ThrottlesLogins;
use Illuminate\Foundation\Home\AuthenticatesAndRegistersUsers;


header("content-type:text/html;charset=utf-8");
class SearchController extends Controller{
	//搜索
	public function search($key = ""){
		if(!empty($_POST)){
			$word = $_POST["keyword"];
		}else{
			$word = $key;
		}
		// var_dump($word);die;
		$search = new \App\Search();
		$keyword = $search->getOne($word);
		if(!is_int($keyword)){
			$arr = [
				"search_time"=>time(),
				"count"=>$keyword->count+1
				];
			$res = $search->search_count($keyword->key_id,$arr);
		}else{
			$data = [
				"keyword"=>$word,
				"search_time"=>time(),
				"count"=>1
				];
			$res = $search->key_add($data);
		}
		$goods = $search->goods_search($word);
		if(is_int($goods)){
			echo '<script>alert("亲，没有你要查询的商品！");window.location.href="http://www.nbshop.com/home/index";</script>';
		}else{
			return view("home/Goodslist",["goods"=>$goods]);
		}
	}
}